#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX = 100;

struct student {
	char name[MAX+10];
	char num[MAX+10];
	int score;
}S[MAX+10];

bool cmp(student a, student b) {
	return a.score > b.score;
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s%s%d", S[i].name, S[i].num, &S[i].score);
	}

	sort(S, S+n, cmp);

	printf("%s %s\n", S[0].name, S[0].num);
	printf("%s %s\n", S[n-1].name, S[n-1].num);

	return 0;
}
